﻿using System;
using System.Windows.Forms;

namespace Landsat8_LSTWindow
{
    public class TextBoxWriter : System.IO.TextWriter
    {
        ListBox lstBox;
        delegate void VoidAction();

        public TextBoxWriter(ListBox box)
        {
            lstBox = box;
        }

        public override void Write(string value)
        {
            VoidAction action = delegate
            {
                lstBox.Items.Add(string.Format("[{0:HH:mm:ss}] {1}", DateTime.Now, value));
            };
            lstBox.BeginInvoke(action);
        }

        public override void WriteLine(string value)
        {
            VoidAction action = delegate
            {
                lstBox.Items.Add(string.Format("[{0:HH:mm:ss}] {1}", DateTime.Now, value));
            };
            lstBox.BeginInvoke(action);
        }

        public override System.Text.Encoding Encoding
        {
            get { return System.Text.Encoding.UTF8; }
        }
    }
   
}
